package com.sx.jys.app.until

import android.text.TextUtils
import com.tencent.mmkv.MMKV

object CacheUntil {
    /**
     * 是否已经登录
     */
    fun isLogin(): Boolean {
        val kv = MMKV.mmkvWithID("app")
        return kv.decodeBool("login", false)
    }

    /**
     * 设置是否已经登录
     */
    fun setIsLogin(isLogin: Boolean) {
        val kv = MMKV.mmkvWithID("app")
        kv.encode("login", isLogin)
    }

    /**
     * 获取token
     */
    fun getToken(): String {
        val kv = MMKV.mmkvWithID("app")
        return kv.decodeString("token", "")
    }

    /**
     * 设置token
     */
    fun setToken(token: String?) {
        val kv = MMKV.mmkvWithID("app")
        if (TextUtils.isEmpty(token)) {
            kv.encode("token", "")
            setIsLogin(false)
        } else {
            kv.encode("token", token)
            setIsLogin(true)
        }
    }

    fun setId(id: String){
        val kv = MMKV.mmkvWithID("app")
        if (TextUtils.isEmpty(id)) {
            kv.encode("uId", "")
            setIsLogin(false)
        } else {
            kv.encode("uId", id)
            setIsLogin(true)
        }
    }

    fun getId(): String {
        val kv = MMKV.mmkvWithID("app")
        return kv.decodeString("uId", "")
    }

    fun showMoreFun():Boolean{
        val ids=mutableListOf<String>("26")
        return !ids.contains(getId())
    }
}